package com.yisu.auction.ewf.common.youzan;

import com.yisu.auction.ewf.common.exception.StageException;
import com.yisu.auction.ewf.common.enums.ResponseCode;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;

/**
 * Created by Administrator on 2016/10/13.
 */
public class KdtApi {
    public static final String CATEGORY_API = "kdt.itemcategories.get";
    public static final String ONSALE_PRODUCT_API = "kdt.items.onsale.get";

    public static String get(String apiEntry, String appId, String appSecret, String api){
        try {
            KdtApiClient kdtApiClient = new KdtApiClient(apiEntry, appId, appSecret);
            HttpResponse response = kdtApiClient.get(api, new HashMap<String, String>());
            return EntityUtils.toString(response.getEntity());
        } catch (Exception e) {
            throw new StageException(ResponseCode.FAILURE.code, ResponseCode.FAILURE.msg);
        }
    }

    public static void main(String args[]) {
        System.out.println(get("http://open.koudaitong.com/api/entry?", "49e6d4fc7fe8dc33cd", "cf56a980761bc73a889d223cd83a80e5",CATEGORY_API ));
        System.out.println(get("http://open.koudaitong.com/api/entry?", "49e6d4fc7fe8dc33cd", "cf56a980761bc73a889d223cd83a80e5",ONSALE_PRODUCT_API ));
    }
}
